﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Controller;
using Interface;

namespace GUI
{
    /// <summary>
    /// Interaction logic for BedømmelseVindue.xaml
    /// </summary>
    public partial class BedømmelseVindue : Window
    {
        MainController controller;
        IMesse aktuelMesse;
        IKonkurrence aktuelKonkurrence;

        public IKonkurrence AktuelKonkurrence
        {
            get { return aktuelKonkurrence; }
            set
            {
                aktuelKonkurrence = value;
                IndlæsKategorier();
            }
        }

        public BedømmelseVindue(MainController controller, IMesse aktuelMesse)
        {
            InitializeComponent();
            this.DataContext = this;

            this.controller = controller;
            this.aktuelMesse = aktuelMesse;

            IndlæsKonkurrencer();
        }

        #region Private Helpers

        private void IndlæsKonkurrencer()
        {
            foreach (IKonkurrence e in controller.HentKonkurrencer(aktuelMesse))
            {
                cb_kategori.Items.Add(e);
            }
        }

        private void IndlæsKategorier()
        {
            Grid myGrid = (Grid)gridKategorier;

            int index = 0;
            foreach (IKategori kategori in controller.HentKategorier(aktuelKonkurrence))
            {
                StackPanel sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                sp.Height = 30;

                Label lbl = new Label();
                lbl.Width = 100;
                lbl.Content = kategori.Navn;

                Label lblPoint = new Label();
                lblPoint.Content = "Antal point: ";

                TextBox txt = new TextBox();
                txt.Width = 40;
                txt.Height = 20;
                txt.Tag = kategori.MaxPoint;
                txt.TextChanged += TextBox_TextChanged;

                Label lblMax = new Label();
                lblMax.Content = "(max: " + kategori.MaxPoint.ToString() + ")";

                sp.Children.Add(lbl);
                sp.Children.Add(lblPoint);
                sp.Children.Add(txt);
                sp.Children.Add(lblMax);

                RowDefinition rowdef = new RowDefinition();

                myGrid.RowDefinitions.Add(rowdef);
                Grid.SetColumn(sp, 0);
                Grid.SetRow(sp, index);
                myGrid.Children.Add(sp);

                if (index == 0)
                     sp.Background = Brushes.Aqua;

                if (index == 1)
                    sp.Background = Brushes.Azure;

                if (index == 2)
                    sp.Background = Brushes.Bisque;

                if (index == 3)
                    sp.Background = Brushes.BlanchedAlmond;


                index++;
            }      

        }

        #endregion

        #region event handlers

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox t = (TextBox)sender;
            MessageBox.Show(t.Tag.ToString() );
        }

        #endregion

    }
}
